#!/bin/bash
#networkspeedtest
# Credit: speedtest https://github.com/sivel/speedtest-cli
# Vars
apptitle="Network SpeedTest"
version="1.0"
# Set Icon directory and file 
export ICNS=$(dirname "${0}")
iconfile="$ICNS/AppIcon.icns"
ApplicationName="/usr/local/bin/python3"

response=$(osascript -e 'tell app "System Events" to display dialog "
Welcome Network Speed Test

You need python3 installed to using this program.\n" buttons {"Cancel", "Network Speed Test"} default button 2 with title "'"$apptitle"' '"$version"'" with icon POSIX file "'"$iconfile"'"  ')

action=$(echo $response | cut -d ':' -f2)

# Exit if Canceled
if [ ! "$action" ] ; then
  osascript -e 'display notification "Program close" with title "'"$apptitle"'" subtitle "User Cancel"'
echo "User Cancel"
  Sleep 1
  echo "QUITAPP"
  exit 0
fi


if [ -f "$ApplicationName" ]; then
    echo "$ApplicationName is installed OK ✅"
else 

    echo "$ApplicationName is not installed ❌
EXIT App in 3 Seconds"
    Sleep 3
    echo "QUITAPP"

fi

# Activate App
osascript <<EOD
  tell application "Network SpeedTest"
      activate
  end tell
EOD

echo "Test Running. Please Wait... "
Sleep 1

echo " "
./speedtest.py
